/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package test;

import abstractmodel.*;
import configure.*;
import dataaccess.*;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author littlechild
 */
public class testDataaccess {
    public static void main(String args[]) {
        try {
            IDataSource data = DataSourceFactory.getDataSource(
                    ConfigureInfo.getProperty(ConfigureInfo.DataSourceClassName));
            IInfo details[]=new IInfo[10];
            
            System.out.println("test save: save 10 entry");
            for(int i=0;i!=10;++i) {
                IInfo detailinfo=new model.DetailInfo();
                details[i]=detailinfo;
                detailinfo.setValue("原因", "test save "+i);
                details[i].setValue("余额",i);
                details[i].setId(i);
                data.saveDetailInfo(details[i]);
            }
            System.out.println("test search");
            ArrayList<IInfo> searchResult=data.search("leftAmount >= 8", details[0].getClass());
            for(IInfo info:searchResult) {
                String titles[]=info.getTitles();
                for(String t:titles) {
                    System.out.println(t+": "+info.getValue(t).getString());
                }
            }
            System.out.println("test change: change the entry");
            for(int i=0;i!=10;++i) {
                details[i].setValue("原因", "test change "+i);
                data.saveDetailInfo(details[i]);
            }
            
            System.out.println("test search");
            searchResult=data.search("leftAmount >= 8", details[0].getClass());
            for(IInfo info:searchResult) {
                String titles[]=info.getTitles();
                for(String t:titles) {
                    System.out.println(t+": "+info.getValue(t).getString());
                }
            }
            
            System.out.println("test delete");
            for(IInfo info: details) {
                data.deleteDetailInfo(info);
            }
             
            System.out.println("test search") ;
            searchResult=data.search("", details[0].getClass());
            for(IInfo info:searchResult) {
                String titles[]=info.getTitles();
                for(String t:titles) {
                    System.out.println(t+": "+info.getValue(t).toString());
                }
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(testDataaccess.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(testDataaccess.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(testDataaccess.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
